<template>
	<view class="indexs box">
		<view class="index_head">
			<view v-if="listNote && listNote.length>1" class="note-box">
				<!-- 为改造成每次循环到下一条时是从后面最开始的地方播放 确无奈添加了一个外层for循环 -->
				<view v-for="item,index in listNote">
					<up-notice-bar @click="goNote(index)" v-if="index==currentIndex" :text="listNote[currentIndex].title" :speed="50" :scrollable="true"></up-notice-bar>
				</view>
			</view>
			<view v-else class="note-box">
				<up-notice-bar @click="goNote(0)" :text="textNote" :speed="50"></up-notice-bar>
			</view>
			<view>
				<u--image :lazy-load="true" radius="8" :src="'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/head.jpg'" width="150px" height="150px" />
			</view>
		</view>
		<view class="index_content">
			<view class="index_content_left" @click="toRecord">
				<view class="index_content_c_bottom">
					<u--image :lazy-load="true" :src="'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/data.jpg'" width="380rpx" height="440rpx" />
				</view>
			</view>
			<view class="index_content_rigth">
				<view class="index_content_rigth_top" @click="toRegime">
					<view class="index_content_c_bottom">
						<u--image :lazy-load="true" :src="'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/doc_new.jpg'" width="350rpx" height="180rpx" />
					</view>
				</view>
				<br />
				<view style="width: 50rpx;height: 36rpx;"></view>
				<view class="index_content_rigth_bottom" @click="toPreinstall">
					<view class="index_content_c_bottom">
						<u--image :lazy-load="true" :src="'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/set_new.jpg'" width="350rpx" height="180rpx" />
					</view>
				</view>
			</view>
		</view>
		<view class="index_content_ops">
			<view class="index_content_ops_left" style="width:100%;margin: 0 30rpx;box-sizing: border-box;" @click="toMsg">
				<view style="display: flex; justify-content: center;align-items: center; width: 100%;">
					<up-icon size="28" color="#F56C6C" name="warning"></up-icon><text style="color: #409EFF;">报警信息</text>
					<up-badge v-if="msgNum > 0" max="999" :value="msgNum"></up-badge>
				</view>
			</view>
			<view class="index_content_ops_left" style="width:100%;margin: 0 30rpx;box-sizing: border-box;" @click="toChants">
				<view style="display: flex; justify-content: center;align-items: center; width: 100%;">
					<up-icon size="24" color="#F56C6C" name="error-circle"></up-icon><text style="color: #409EFF;">预警统计</text>
				</view>
			</view>
		</view>
		<!-- <view class="index_content_ops">
			<view class="index_content_ops_left" style="width:100%;margin: 0 30rpx;box-sizing: border-box;" @click="toGeneralSituation">
				<view style="display: flex; justify-content: center;align-items: center; width: 100%;">
					<up-icon size="28" color="#67C23A" name="warning"></up-icon><text
						style="color: #409EFF;">消防单位概况</text>
					<up-badge v-if="msgNum > 0" max="999" :value="msgNum"></up-badge>
				</view>
			</view>
		</view> -->
		<view v-if="user && (user.power == 1 || user.power == 2)" style="padding: 30rpx 0 20rpx 0;">
			<fui-section title="各单位消防日志记录情况" isLine></fui-section>
		</view>
		<view v-if="user && (user.power == 1 || user.power == 2)" class="bg_fff" style="padding: 20rpx 0;">
			<view class="bg_fff com_width">
				<u-input type="text" placeholder="请输入搜索内容" v-model="serachVal" @blur="searchFun" />
			</view>
		</view>
		<view v-if="user && (user.power == 1 || user.power == 2)" class="index_content_record">
			<view style="width: 95%; height: 100%; margin: auto;">
				<view>
					<u-tabs :list="list" @click="onRecord"></u-tabs>
				</view>
				<scroll-view style="height:700rpx;" scroll-y>
					<view style="margin-top:20rpx;" v-if="recordIndex == 0">
						<fui-list>
							<fui-list-cell arrow v-for="(item,index) in units" :key="index" @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#2979ff" size="35" name="order-fill"></fui-icon>
									<!-- #ifdef H5 -->
									<view class="overflow">单位名称：{{item.unitName}}</view>
									<!-- #endif -->
									<!-- #ifndef H5 -->
									<rich-text class="overflow">单位名称{{item.unitName}}</rich-text>
									<!-- #endif -->
								</view>
							</fui-list-cell>
						</fui-list>
					</view>
					<view style="margin-top:20rpx;" v-if="recordIndex == 1">
						<up-collapse :border="false">
							<up-collapse-item v-for="(group,index) in unitGroupList" :key="index" :title="'区域：'+group.groupsName" :name="group.id" :border="false">
								<fui-list>
									<fui-list-cell v-for="item in group.unitList" arrow @click="toUnits(item)">
										<view class="routine-text">
											<rich-text style="margin-left:4rpx;">{{item.unitName}}</rich-text>
										</view>
									</fui-list-cell>
								</fui-list>
							</up-collapse-item>
						</up-collapse>
					</view>
					<view style="margin-top:20rpx;" v-if="recordIndex == 2">
						<up-collapse :border="false">
							<up-collapse-item v-for="(type,index) in unitTypeList" :key="index" :title="'类型：'+type[0]" :name="index" :border="false">
								<fui-list>
									<fui-list-cell arrow :key="index" v-for="(item,index) in type[1]" @click="toUnits(item)">
										<view class="routine-text">
											<rich-text>{{item.unitName}}</rich-text>
										</view>
									</fui-list-cell>
								</fui-list>
							</up-collapse-item>
						</up-collapse>
					</view>
					<view style="margin-top: 20rpx;" v-if="recordIndex == 3">
						<view>
							<up-button @click="showUnitTime = true" :text="title + unitTitle"></up-button>
						</view>
						<fui-list :key="index" v-for="(item,index) in unitsSortdata">
							<fui-list-cell arrow @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#2979ff" size="35" name="order-fill"></fui-icon>
									<rich-text>单位名称：{{item.unitName}}</rich-text>
								</view>
							</fui-list-cell>
							<fui-list-cell arrow v-if="item.daysSinceToday == 0" @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#ff0000" size="35" name="menu"></fui-icon>
									<rich-text>距离到期时间还有：{{item.daysSinceToday}}天</rich-text>
								</view>
							</fui-list-cell>
							<fui-list-cell arrow v-if="item.daysSinceToday < 0" @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#ff0000" size="35" name="menu"></fui-icon>
									<rich-text>已过期：{{item.daysSinceToday}}天</rich-text>
								</view>
							</fui-list-cell>
							<fui-list-cell arrow v-if="item.daysSinceToday > 0" @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#ff0000" size="35" name="menu"></fui-icon>
									<rich-text>距离到期时间还有：{{item.daysSinceToday}}天</rich-text>
								</view>
							</fui-list-cell>
							<fui-list-cell arrow v-if="!item.fireMaintenanceExpirationTime">
								<view class="routine-text" @click="toUnits(item)">
									<fui-icon color="#5500ff" size="35" name="slide"></fui-icon>
									<rich-text>合同期限：未填写维保合同期限</rich-text>
								</view>
							</fui-list-cell>
							<fui-list-cell arrow v-if="item.fireMaintenanceExpirationTime" @click="toUnits(item)">
								<view class="routine-text">
									<fui-icon color="#5500ff" size="35" name="slide"></fui-icon>
									<rich-text>合同期限：{{item.fireMaintenanceExpirationTime}}</rich-text>
								</view>
							</fui-list-cell>
						</fui-list>
					</view>
				</scroll-view>
			</view>
		</view>
		<view>
			<u-picker title="请选择时间分类" @confirm="onUniTime" @cancel="showUnitTime = !showUnitTime" :show="showUnitTime" :columns="uniTimecolumns"></u-picker>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view>
			<up-modal :show="isAppUpData" @cancel="isAppUpData=!isAppUpData" title="发现新版本" :content="description" showCancelButton cancelText="稍后再说" confirmText="立即更新" cancelColor="#909399" confirmColor="#409EFF" @confirm="onAppUpData" ref="uModal"></up-modal>
		</view>
		<view>
			<up-modal :show="isAppUpDataSon" @cancel="isAppUpDataSon=!isAppUpDataSon" title="发现新版本" :content="description" cancelText="稍后再说" confirmText="立即更新" cancelColor="#909399" confirmColor="#409EFF" @confirm="onAppUpData" ref="uModal"></up-modal>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import { BASE_IP } from '@/common/http/url.js'
	// #ifdef APP-PLUS
	const open = uni.requireNativePlugin("Html5App-openFile");
	// #endif
	// #ifdef MP-WEIXIN || H5
	const open = '';
	// #endif
	export default {
		data() {
			return {
				searUnit: null,
				amapPlugin: null,
				msgNum: 0,
				active: 0,
				vTabs: false,
				value1: 0,
				flag: false,
				tabs: ['消防记录概况', '消防单位概况'],
				index: 0,
				recordopslist: [{ id: 0, name: "防火检查记录概况" }, { id: 1, name: "防火巡查记录概况" }, { id: 2, name: "消防栓制室值班记录" }],
				user: null,
				units: [],
				allunits: [],
				list: [{ name: '单位' }, { name: '监管区域' }, { name: '经营类型' }, { name: '维保合同' }],
				recordIndex: 0,
				showUnitTime: false,
				uniTimecolumns: [
					['全部', '30天', '60天', '90天']
				],
				title: "时间分类：",
				unitTitle: "全部",
				unitsSortdata: [],
				day: 0,
				preset: "",
				deviceId: "",
				isAppUpData: false,
				isAppUpDataSon: false, //强制更新
				description: "", //更新描述
				serachVal: null,
				unitGroupList: null,
				unitTypeList: null,
				activeUnitGroup: [0, 1, 2],
				textNote: '欢迎使用消防重点单位智能管理系统',
				listNote: null,
				currentIndex: 0,
				timer: null,
				forceUpdate: 0,
			}
		},
		onShow() {
			/**
			 * 特别注意
			 * 首页这里要把数据加载放在onShow事件 这是因为登录页面wxLogin返回首页时使用uni.switchTab 此时进入页面是不执行onLoad的造成数据白屏的bug
			 * 另外 Java后端使用了sa-token没有持久化，需待改造成redis 这里增加一个auto/login 用于首页再次更新用户信息数据 避免Java重启后token失效而未识别当前的user信息
			 */
			this.user = uni.getStorageSync("user");
			console.log("用户对象", this.user);
			if (this.user != null && this.user != '') {
				if (this.user.openid != '') {
					//避免因Java服务重启造成Java无法识别用户信息的bug，这里仅在首页更新登录信息，待改进
					let url = BASE_IP + "pc/wx/user/auto/login?openId=" + this.user.openid
					uni.request({
						method: "POST",
						url: url,
						success: (res) => {
							console.log("openId登录", res.data)
							if (res.statusCode == 200) {
								this.user = res.data.msg;
								uni.setStorageSync('user', this.user);
								this.loadData();
							}
						}
					})
				} else {
					this.loadData();
				}
			}
		},
		onPullDownRefresh() {
			this.loadData();
			setTimeout(() => {
				//结束下拉刷新
				uni.stopPullDownRefresh();
			}, 1000);
		},
		mounted() {
			//this.startAutoScroll();
		},
		beforeDestroy() {
			this.stopAutoScroll();
		},
		onHide() {
			this.stopAutoScroll();
		},
		methods: {
			loadData() {
				//this.appVersion()
				this.getHome()
				this.getUnit()
				this.getServerData()
				this.getUserReminder()
				this.getPrall()
				this.initPresetFeatureSettin()
				this.initCid()
				this.getMsgNum()
				if (this.user.power == 1 || this.user.power == 2) {
					this.getUnitList()
					this.getUnitGroup()
					this.unitsSort(0)
				}
				if (uni.getSystemInfoSync().platform === 'android') {
					let is = open.isLoadTbs();
					if (!is) {
						this.installLocalTbs()
						return
					}
				}
				uni.getSystemInfo({
					success: (res) => {
						console.log(res.deviceId)
						this.deviceId = res.deviceId
					}
				})
				if (this.user.power != '1') {
					this.list = [{ name: '单位' }, { name: '监管区域' }, { name: '经营类型' }]
				}
			},
			calculateScrollTime(text) {
				const baseTime = 3000; // 基础时间2秒
				const charTime = 200; // 每个字符增加100毫秒
				return baseTime + (text.length * charTime);
			},
			startAutoScroll() {
				if (!this.listNote || this.listNote.length === 0) return;
				const currentText = this.listNote[this.currentIndex].title;
				const scrollTime = this.calculateScrollTime(currentText);
				console.log('sa', currentText, scrollTime);
				this.timer = setTimeout(() => {
					this.currentIndex = (this.currentIndex + 1) % this.listNote.length;
					this.forceUpdate++;
					this.startAutoScroll(); // 递归调用
				}, scrollTime);
			},
			stopAutoScroll() {
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = null;
				}
			},
			goNote(index) {
				if (this.listNote && this.listNote.length > 0) {
					uni.navigateTo({ url: "/pages/index/note?id=" + this.listNote[index].id });
				}
			},
			getHome() {
				uni.request({
					url: BASE_IP + "pc/unit/home",
					method: "GET",
					header: { "Authorization": this.user.token },
					success: (res) => {
						console.log('home', res);
						if (res.statusCode == 200) {
							if (res.data.data != null) {
								let list = res.data.data;
								for (let i in list) {
									if (list[i].name == 'note') {
										if (list[i].list && list[i].list.length > 0) {
											this.listNote = list[i].list;
											if (this.listNote.length == 1) {
												//只有一条就不循环播放了
												this.textNote = this.listNote[0].title;
											} else {
												this.startAutoScroll();
											}
										}
									}
								}
							}
						}
					},
					fail: (res) => {
						console.log("home.error", res)
					}
				})
			},
			searchFun(e) {
				console.log(this.allunits)
				if (e != '') {
					this.units = this.allunits.filter(res => {
						return res.unitName.indexOf(e) > -1
					})
				} else {
					this.units = this.allunits
				}
			},
			getMsgNum() {
				let _this = this;
				let url = BASE_IP + "pc/msg/msg/num"
				uni.request({
					header: {
						"Authorization": _this.user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "GET",
					success: (res) => {
						console.log(res)
						if (res.statusCode == 200) {
							this.msgNum = res.data
						}
					},
					fail: () => {}
				})
			},
			installLocalTbs() {
				let url = BASE_IP + "static/tbs/arm64-v8a.tbs"
				uni.downloadFile({
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							uni.saveFile({
								tempFilePath: res.tempFilePath,
								success: (r) => {
									let filepath = plus.io.convertLocalFileSystemURL(r
										.savedFilePath);
									open.installLocalTbs({
										tbsFilePath: filepath,
										isdelete: true //安装好是否要删除该文件
									}, function(e) {
										// console.log("安装 tbs 内核" + JSON.stringify(e));
										// if (e.code == 0) {
										// 	uni.showToast({
										// 		title: "安装TBS 请重新打开",
										// 		icon: "none"
										// 	});
										// } else {
										// 	uni.showToast({
										// 		title: e.msg,
										// 		icon: "none"
										// 	});
										// }
									});
								}
							})
						}
					}
				})
				//安装 tbs 离线内核, 在适当的时候安装tbs 浏览内核,安装一次即可
			},
			/**
			 * 获取天气和地理位置信息
			 */
			getWeatherAndGeographicInfo() {
				uni.getLocation({
					altitude: true,
					success: (res) => {
						let lat = res.latitude
						let log = res.longitude
						let url = BASE_IP + "pc/map/infos/" + lat + "/" + log
						let user = uni.getStorageSync("user")
						uni.request({
							header: {
								"Authorization": user.token,
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							url: url,
							method: "GET",
							success: (res) => {
								if (res.data.code == 1) {
									let data = JSON.parse(res.data.data)
									console.log("获取地理位置信息：", data)
								}
							}
						})
					}
				})
			},
			onAppUpData() {
				plus.runtime.openURL('https://www.pgyer.com/eerFcP', function(err) {
					uni.showToast({
						title: JSON.stringify(err),
						duration: 8000
					})
				});
			},
			toGeneralSituation() {
				uni.navigateTo({
					url: "/pagesMine/unitProfile/unitProfile"
				})
			},
			toPreinstall() {
				uni.navigateTo({
					url: "/pagesWork/preinstall/preinstall"
				})
			},
			toRegime() {
				uni.navigateTo({
					url: "/pages/regime/regime"
				})
			},
			toRecord() {
				uni.navigateTo({
					url: "/pagesWork/record/record"
				})
			},
			toMsg() {
				uni.navigateTo({
					url: "/pagesMine/notificationCenter/notice/notice"
				})
			},
			toChants() {
				uni.navigateTo({
					url: "/pagesWork/warningCharts/warningCharts"
				})
			},
			appVersion() {
				const systemInfo = uni.getSystemInfoSync();
				let v = systemInfo.appWgtVersion
				let code = systemInfo.appVersionCode
				let url = BASE_IP + "pc/iotFireAlarmRecord/version/temp"
				uni.request({
					header: {
						"Authorization": this.user.token,
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					url: url,
					method: "GET",
					success: (res) => {
						console.log("检查更新：", res)
						if (res.statusCode == 401) {
							uni.clearStorageSync()
							uni.clearStorage()
							uni.redirectTo({ url: "/pages/login/login" })
							return
						}
						if (res.statusCode == 404) {
							uni.clearStorageSync()
							uni.clearStorage()
							uni.redirectTo({
								url: "/pages/login/login"
							})
							return
							// plus.runtime.restart();
						}
						if (res.statusCode == 500) {
							uni.clearStorageSync()
							uni.clearStorage()
							uni.redirectTo({
								url: "/pages/login/login"
							})
							return
							// plus.runtime.restart();
						}
						if (res.statusCode == 200) {
							console.log("请求的数据", res.data)
							if (res.data.code == 500) {
								let msg = res.data.msg
								if (msg == "未提供Token") {
									console.error(msg)
									uni.clearStorageSync()
									uni.clearStorage()
									uni.setStorageSync('url', '');
									uni.redirectTo({
										url: "/pagesMine/wxLogin/wxLogin"
									})
									return
								}
								uni.showModal({
									title: "提示",
									content: res.data.msg,
									showCancel: false,
									success: (r) => {
										if (r.confirm) {
											uni.clearStorageSync()
											uni.clearStorage()
											uni.redirectTo({
												url: "/pages/login/login"
											})
										}
									}
								})
							}
							this.description = res.data.description
							console.log("code：", code)
							if (code >= res.data.versionCode) {
								console.log("最新版")
								this.isAppUpData == false
								this.isAppUpDataSon = false
								uni.showTabBar()
							} else {
								if (res.data.isCompulsion == 0) {
									this.isAppUpData = true
									// #ifdef APP-PLUS
									uni.hideTabBar()
									// #endif

								}
								if (res.data.isCompulsion == 1) {
									this.isAppUpDataSon = true
									// #ifdef APP-PLUS
									uni.hideTabBar()
									// #endif
								}
							}
						}

					},
					fail: () => {
						uni.clearStorageSync()
						uni.clearStorage()
						uni.redirectTo({
							url: "/pages/login/login"
						})
						return
						// plus.runtime.restart();
					}
				})

				console.log("==========>", v)
			},
			initCid() {
				uni.getPushClientId({
					success: (res) => {
						console.log("设置用户通知ID")
						console.log(res.cid);

						let url = BASE_IP + "pc/user/ntifyId/" + this.user.uuid + "/" + res.cid
						uni.request({
							header: {
								"Authorization": this.user.token,
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							url: url,
							method: "PUT",
							success: (res) => {
								console.log(res)
								if (res.statusCode == 200) {


								}
								if (res.statusCode == 404) {

								}
								if (res.statusCode == 500) {

								}
							},
							fail: () => {
								uni.showToast({
									title: "提交失败",
									icon: "error"
								})
							}
						})
					},
					fail(err) {
						console.log(err)
					}
				})



			},

			initPresetFeatureSettin() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/presetFeatureSettin/" + user.unitId
				// console.log(url)
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					success: (res) => {
						// console.log(res)
						uni.setStorageSync("recordTable", res.data)

					},
					fail: (res) => {
						uni.showToast({
							title: "服务器请求失败",
							icon: "error"
						})
						return
					}
				})
			},
			getPrall() { //获取预设功能对象数据
				// console.log("调用111111111111111111111111111")
				let user = uni.getStorageSync("user")
				// console.log(user)
				// this.user = user
				let url = BASE_IP + "pc/presetfunction/find/presetFunction/" + user.unitId + "/" + user.uuid
				uni.request({
					header: {
						"Authorization": user.token,
					},
					url: url,
					success: (res) => {
						// console.log("请求成功：",res)
						// uni.removeStorageSync("pralldata")
						uni.setStorageSync("pralldata", res.data)
						// console.log("pralldata", res.data)
					},
					fail: (res) => {
						// console.log("请求失败：", res)
					}
				})
			},
			getUnit() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/query/" + user.userName
				uni.request({
					url: url,
					header: { "Authorization": user.token },
					success: (res) => {
						if (res.statusCode == 200 && res.data != null) {
							if (res.data.unitDistrict) {
								let title = res.data.unitDistrict + "消防重点单位智能管理系统"
								uni.setNavigationBarTitle({ title: title })
							}
						}
					},
					fail: () => {
						uni.showToast({
							title: "服务器出现问题",
							icon: "error"
						})
					}
				})
			},
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let url = BASE_IP + "pc/iotFireAlarmRecord/query/" + this.user.unitId
					uni.request({
						header: {
							"Authorization": this.user.token
						},
						url: url,
						success: (res) => {
							// console.log(res)
							uni.setStorageSync("chart", res.data)
						}
					})
					let charts = uni.getStorageSync("chart")

					let res = {
						categories: [],
						series: []
					};
					let temp = {
						name: "感烟火灾探测器",
						data: [],
						color: ""
					}

					let temp1 = {
						name: "复合火灾探测器",
						data: [],
						color: ""
					}
					let temp2 = {
						name: "火警",
						data: [],
						color: ""
					}
					let temp3 = {
						name: "火警错报",
						data: [],
						color: ""
					}
					let temp4 = {
						name: "故障报警",
						data: [],
						color: ""
					}
					let temp5 = {
						name: "监管报警",
						data: [],
						color: ""
					}
					let categories = []
					for (let index in charts) {
						if (charts[index] && charts[index].smokeFireDetector) {
							temp.data.push(charts[index].smokeFireDetector)
							temp1.data.push(charts[index].compositeFireDetector)
							temp2.data.push(charts[index].fireAlarm)
							temp3.data.push(charts[index].fireAlarmFalseAlarm)
							temp4.data.push(charts[index].malfunction)
							temp5.data.push(charts[index].supervisionAlarm)
							res.categories.push(charts[index].date)
						}
					}
					res.series.push(temp)
					res.series.push(temp1)
					res.series.push(temp2)
					res.series.push(temp3)
					res.series.push(temp4)
					res.series.push(temp5)
					let obj = {
						temp: temp,
						temp1: temp1,
						temp2: temp2,
						temp3: temp3,
						temp4: temp4,
						temp5: temp5,
					}

					uni.setStorageSync("chartson", obj)
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			toCharView(data) {
				uni.navigateTo({
					url: "/pages/chartView/chartView?mid=" + data
				})
			},
			getUnitList() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/getAll"
				uni.request({
					header: { "Authorization": user.token },
					method: "GET",
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							this.units = res.data;
							uni.setStorageSync("units", this.units);
							this.allunits = JSON.parse(JSON.stringify(this.units));
							const map = new Map();
							this.allunits.forEach(item => {
								if (!map.has(item.unitType)) {
									map.set(item.unitType, []);
								}
								map.get(item.unitType).push(item);
							});
							this.unitTypeList = map;
							console.log('uu', this.unitTypeList);
						}
					}
				})
			},
			getUnitGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/getUnitGroup"
				uni.request({
					header: { "Authorization": user.token },
					method: "GET",
					url: url,
					success: (res) => {
						console.log("getUnitGroup", res);
						if (res.statusCode == 200) {
							this.unitGroupList = res.data;
							this.activeUnitGroup = this.unitGroupList.map(item => item.id);
							console.log('aa', this.activeUnitGroup);
						}
					}
				})
			},
			toUnits(item) {
				console.log("参数", item)
				uni.navigateTo({
					url: "/pages/chartView/unitCharView?unit=" + JSON.stringify(item)
				})
			},
			onRecord(res) {
				this.recordIndex = res.index
			},
			onUniTime(res) {
				let day = 0
				if (res.indexs == 0) {
					this.unitTitle = "全部"
					day = 0
					this.unitsSort(day)
				}
				if (res.indexs == 1) {
					this.unitTitle = "30天"
					day = 30
					this.unitsSort(day)
				}
				if (res.indexs == 2) {
					this.unitTitle = "60天"
					day = 60
					this.unitsSort(day)
				}
				if (res.indexs == 3) {
					this.unitTitle = "90天"
					day = 90
					this.unitsSort(day)
				}
				this.showUnitTime = false
			},
			unitsSort(day) {
				let data = this.units;
				const today = new Date().setHours(0, 0, 0, 0); // 获取当前日期的时间戳，忽略时间部分
				console.log("---------------data", data)
				if (!data) {
					return;
				}
				data.forEach(obj => {
					if (obj.fireMaintenanceExpirationTime) {
						const expirationTime = new Date(obj.fireMaintenanceExpirationTime).setHours(0, 0,
							0,
							0); // 获取过期日期的时间戳，忽略时间部分
						const daysDifference = Math.floor((expirationTime - today) / (24 * 60 * 60 *
							1000)); // 计算天数差
						obj.daysSinceToday = daysDifference;
					} else {
						obj.daysSinceToday = 0;
					}
				});

				if (day === 0) {
					data.sort((a, b) => new Date(a.fireMaintenanceExpirationTime) - new Date(b
						.fireMaintenanceExpirationTime));
				} else {
					data = data.filter(obj => obj.daysSinceToday <= day);
					data.sort((a, b) => a.daysSinceToday - b.daysSinceToday);
				}

				this.unitsSortdata = data;
			},
			getUserReminder() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/classification/query/" + user.uuid
				let _this = this
				uni.request({
					url: url,
					header: {
						"Authorization": user.token
					},
					success: (res) => {
						uni.setStorageSync("reminder", res.data)
					}
				})
			},
		},

	}
</script>

<style lang="scss">
	.routine-text {
		display: flex;
		align-items: center;
	}

	.box {
		//参数解释请往下看
		// background-size: cover;
		// background-repeat: no-repeat;
		// background-position: center center;
		background: linear-gradient(to bottom, #B5DEFC 0%, #F7FBFF 100%);
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
		height: 100vh;
		width: 100vw
	}

	.indexs {
		// width: 95%;
		// height: 100%;
		margin: 0 auto;
	}

	.index_head {
		width: 100%;
		box-sizing: border-box;
		padding: 0 30rpx;
		height: 25%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.index_content {
		width: 100%;
		box-sizing: border-box;
		padding: 0 30rpx;
		height: 450rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.index_content_left {
		width: 45%;
		height: 100%;
		background-color: #fff;
		/* 设置背景颜色，带有一定的透明度 */
		border: solid 1px #F2F6FC;
		border-radius: 8px;
		backdrop-filter: blur(2px);
		/* 设置毛玻璃效果，模糊半径为5px，你可以根据需要调整此值 */
		display: flex;
		flex-direction: column;
		justify-content: center;
		/* 在垂直方向上居中对齐子元素 */
		align-items: center;
		/* 在水平方向上居中对齐子元素 */
		height: 100%;
		/* 设置父元素高度为100% */
		overflow: hidden;
	}

	.index_content_c_top {

		display: flex;
		justify-content: center;
		align-items: center;
	}

	.index_content_c_bottom {

		border-bottom-right-radius: 8px;
		border-bottom-left-radius: 8px;

		display: flex;
		justify-content: center;
		align-items: center;
		overflow: hidden
	}

	.index_content_rigth {
		width: 50%;
		height: 100%;

		display: flex;
		flex-direction: column;
		justify-content: center;
		/* 在垂直方向上居中对齐子元素 */
		align-items: center;
		/* 在水平方向上居中对齐子元素 */
		height: 100%;
		/* 设置父元素高度为100% */
	}

	.index_content_rigth_top {
		width: 100%;
		height: 200rpx;
		background-color: #fff;
		/* 设置背景颜色，带有一定的透明度 */
		border: solid 1px #F2F6FC;
		border-radius: 8px;
		backdrop-filter: blur(2px);
		/* 设置毛玻璃效果，模糊半径为5px，你可以根据需要调整此值 */
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.index_content_rigth_bottom {
		width: 100%;
		height: 200rpx;
		background-color: #fff;
		/* 设置背景颜色，带有一定的透明度 */
		border: solid 1px #F2F6FC;
		border-radius: 8px;
		backdrop-filter: blur(2px);
		/* 设置毛玻璃效果，模糊半径为5px，你可以根据需要调整此值 */
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.index_content_c_top_son {
		position: absolute;
		bottom: 8px;
		right: 20px;
	}

	.index_content_ops {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding-top: 50rpx;
	}

	.index_content_ops_left {
		height: 70%;
		background-color: #fff;
		/* 设置背景颜色，带有一定的透明度 */
		border: solid 1px #F2F6FC;
		border-radius: 8px;
		backdrop-filter: blur(2px);
		display: flex;
		justify-content: center;
		align-content: center;
	}

	.index_content_ops_rigth {
		height: 70%;
		width: 45%;
		background-color: #fff;
		/* 设置背景颜色，带有一定的透明度 */
		border: solid 1px #F2F6FC;
		border-radius: 8px;
		backdrop-filter: blur(2px);
		display: flex;
		justify-content: center;
		align-content: center;
	}

	.index_content_record {
		/* 设置背景颜色，带有一定的透明度 */
		width: 98%;
		height: auto;
		margin: 0 auto;
		border-radius: 18rpx;
		background-color: #fff;
	}

	.banner {
		padding: 30rpx;
	}

	.note-box {
		width: 380rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}
</style>